package com.test.springmvc;


import com.test.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/model")
@SessionAttributes(types = {String.class},value = {"username","email","age"})
public class ModelCtrl {

    @RequestMapping(value = "/test1")
    public ModelAndView test1(ModelAndView modelAndView){
        modelAndView.addObject("username","admin");
        modelAndView.addObject("email","yyy@qq.com");
        modelAndView.addObject("age","23");
        modelAndView.setViewName("login");

        return modelAndView;
    }

    @RequestMapping(value = "/test2")
    public String test2(Model model){
        model.addAttribute("username","test");
        model.addAttribute("email","111@qq.com");
        model.addAttribute("age","22");
        return "login";
    }

    @RequestMapping(value = "/test3")
    public String test3(@ModelAttribute("username") String username,@ModelAttribute("email") String email,
                        @ModelAttribute("age") String age){

        return "login";
    }


}
